package com.alaia.alaiaauth.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alaia.alaiacommoncore.auth.model.LoginAppUser;
import com.alaia.alaiacommoncore.model.SysUser;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (StrUtil.isBlank(username)) {
            throw new UsernameNotFoundException("登录用户：" + username + " 不存在");
        }
        // 查出密码
//        UserVO userVO = systemService.loadUserByUsername(username);
        SysUser sysUser = new SysUser();
        sysUser.setPassword("123456");
        sysUser.setUserName("admin");
        if (ObjectUtil.isNull(sysUser)) {
            throw new UsernameNotFoundException("登录用户：" + username + " 不存在");
        }
        return new LoginAppUser(sysUser, "192.168.0.1", LocalDateTime.now(), 1);
    }
}
